package net.lovesrc.allin.jobs.backup;

import com.alibaba.fastjson.JSONObject;
import net.lovesrc.allin.biz.lbc.BaseLbcService;
import net.lovesrc.allin.biz.lbc.LbcService;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;

//@Component
@Profile("geliclive")
public class LbcBuyKJJob extends LbcBaseJob {

    @Autowired
    private LbcService lbcService;

    @Override
    public void runOnce() throws Exception {

        {
            JSONObject row = queryForRow(jdbcTemplate, "select mobile from t_lbc_account where goldAccount + silverAccount > 30 and cpValue = 0 and mine = 0 limit 1");
            if (row != null) {
                lbcService.updateRepeatBuyJy(row.getString("mobile"), true);
            }
        }

        {
            JSONObject row = queryForRow(jdbcTemplate, "select mobile from t_lbc_account where repeatBuyKj = 1 and cpValue < 0.03 and goldAccount + silverAccount > 10 limit 1");
            if (row != null) {
                lbcService.buyKj4CPValue(row.getString("mobile"), 0.03, BaseLbcService.Proxy.PROXY_GELIC);
            }
        }

    }

    @Override
    protected long intervalMilliseconds() {
        return 1000 * RandomUtils.nextInt(30, 90);
    }

}
